<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      box-sizing: border-box;
    }
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      margin: 0;
      height: 100vh;
      overflow: hidden;
      text-align: center;
    }
    .key {
      display: inline-flex;
      position: relative;
      flex-direction: column;
      align-items: center;
      border: 1px solid #eee;
      box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
      padding: 20px;
      font-size: 20px;
      font-weight: bold;
      margin: 10px;
      min-width: 150px; 
    }
    .key small {
      position: absolute;
      top: -24px;
      /* left: 0; */
      font-size: 14px;
      text-align: center;
      color: #555;
    }
    @media (max-width: 768px) {
      .key {
        margin: 10px 0;
      }
    }
  </style>
</head>
<body>
  <div id="insert">
    <div class="key">
      请按下键盘
    </div>
  </div>

  <script>
    const insert = document.getElementById("insert");
    window.addEventListener("keydown", (event) => {
      insert.innerHTML = `
      <div class="key">
        <small>event.key</small>
        ${event.key === " " ? "space" : event.key}
      </div>
      <div class="key">
        <small>event.keyCode</small>
        ${event.keyCode}
      </div>
      <div class="key">
        <small>event.code</small>
        Key${event.keyCode}
      </div>
      `
    })
  </script>
</body>
</html>